package com.wh.concurrent.threadlocal;

public class TestNum {

	private ThreadLocal<Integer> threadLocal = new ThreadLocal<Integer>();
	
	public Integer getNum() {
		if(threadLocal.get() == null) {
			threadLocal.set(0);
		} else {
			threadLocal.set(threadLocal.get() + 1);
		}
		return threadLocal.get();
	}
	
	public static void main(String[] args) {
		final TestNum testNum = new TestNum();
		Runnable runnable = new Runnable() {
			
			@Override
			public void run() {
				for(int i = 0; i < 3; i++) {
					System.out.println(Thread.currentThread().getName() + ":" + testNum.getNum());
				}
				
			}
		};
		new Thread(runnable).start();
		new Thread(runnable).start();
		new Thread(runnable).start();
	}
}
